/**
 * Created by jianglinjie on Thu Sep 21 2017
 * @flow
 */
'use strict';
import type { RegisterParam, RegisterResult } from './types';
import { ErrorCode } from '../../constants';
import strategyMap from './strategy/strategyMap';
import { createError } from '../../utils/ErrorUtils';

class RegisterService {
  async register(type: string, param: RegisterParam): Promise<RegisterResult> {
    let strategy = strategyMap.get(type);
    if (strategy) {
      let result = await strategy.register(param);
      return result;
    } else {
      throw createError(400, '不支持的注册类型', ErrorCode.UNSUPPORT_REGISTER_TYPE);
    }
  }
}

export default new RegisterService();